package com.java.model;

import lombok.Data;

import java.io.Serializable;

/**
 * 响应前端的通用对象
 */

@Data
public class Result implements Serializable {

    private static final long serialVersionUID = 5712367830031773930L;
    /**
     * 响应代码
     */
    private String code;

    /**
     * 响应内容
     */
    private String msg;

    /**
     * 响应数据
     */
    private Object data;

    /**
     * 查询的总数
     */
    private Long count;

    public Result() {}
    public Result(String code, String msg, Object data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public static Result success() {
        return new Result("0", null, null, null);
    }

    public static Result success(Object data, Long count) {
        return new Result("0", null, data, count);
    }

    public static Result error(String msg) {
        return new Result("1", msg, null, null);
    }
}
